/*
 * @Authoryour name
 * @Date2020-12-02 22:04:47
 * @LastEditTime2020-12-03 23:01:13
 * @LastEditorsyour name
 * @DescriptionIn User Settings Edit
 * @FilePath\STM32H750_FreeRTOS\User\application\shell\shell_hash.h
 */ 
#ifndef _SHELL_HASH_H_
#define _SHELL_HASH_H_

#include "common_types.h"

#define HASH_MAX_BUCKETS_NUM       32
#define HASH_MAX_NODE_NUM          4

typedef struct hash_data
{
    char *key;
    uint16_t keylen;
    uint16_t value;
}hash_data_t;

typedef struct hash_node
{
    hash_data_t data;
    struct hash_node *prev;
    struct hash_node *next;
}hash_node_t;

typedef struct hash_bucket
{
    uint16_t node_num;
    hash_node_t *head;
    hash_node_t *tail;
}hash_bucket_t;

typedef struct hash_table
{
    hash_bucket_t buckets[HASH_MAX_BUCKETS_NUM];
}hash_table_t;

extern void hash_init(hash_table_t *table);
extern boolean hash_find(hash_table_t *table, char *key, uint16_t keylen, uint16_t *pvalue);
extern void hash_add(hash_table_t *table, char *key, uint16_t keylen, uint16_t value);

#endif








